package com.gcosc.hly.codejava.controller;

import com.gcosc.hly.codejava.entity.Paper;
import com.gcosc.hly.codejava.filter.AuthRoot;
import com.gcosc.hly.codejava.params.QueryParams;
import com.gcosc.hly.codejava.result.Result;
import com.gcosc.hly.codejava.service.PaperService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 试卷
 * */
@RestController
@RequestMapping("/api/paper")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PaperController {

    private final PaperService paperService;

    @GetMapping("/{id}")
    public Result detail(@PathVariable int id){
        return Result.ok(paperService.detail(id));
    }

    @GetMapping("/id/{id}")
    public Result getById(@PathVariable int id){
        return Result.ok(paperService.getById(id));
    }

    @GetMapping("/list")
    public Result list(QueryParams params){
        return Result.ok(paperService.queryParams(params));
    }

    @PostMapping("/edit")
    @AuthRoot
    public Result edit(@RequestBody Paper paper){
        return Result.ok(paperService.edit(paper));
    }

    @PostMapping("/del/{ids}")
    @AuthRoot
    public Result del(@PathVariable String ids){
        paperService.removeBatchByIds(Arrays.asList(ids.split(",")));
        return Result.ok();
    }

    @GetMapping("/statistics/{id}")
    @AuthRoot
    public Result statistics(@PathVariable String id){
        return Result.ok(paperService.getStatisticsById(id));
    }

    @GetMapping("/data/{id}")
    @AuthRoot
    public Result data(@PathVariable String id){
        return Result.ok();
    }
}
